package cn.jiadakeji.parent.service.impl;

import cn.jiadakeji.parent.domain.TermTeacherRelation;
import cn.jiadakeji.parent.dto.TermTeacherRelationDTO;
import cn.jiadakeji.parent.mapper.TermTeacherRelationMapper;
import cn.jiadakeji.parent.service.TermTeacherRelationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author heyanfeng
 * @create 2022-03-14 10:47
 */
@Service
public class TermTeacherRelationServiceImpl extends ServiceImpl<TermTeacherRelationMapper, TermTeacherRelation> implements TermTeacherRelationService {

    private final static String MALE = "男";
    private final static String FEMALE = "女";
    private final static String MAIN_TEACHER = "主讲老师";
    private final static String ASSISTANT_TEACHER = "助教老师";
    private final static String MALE_TYPE = "1";
    private final static String ASSISTANT_TYPE = "1";

    /**
     * 获取上课教师信息
     */
    @Override
    public List<TermTeacherRelationDTO> getTermTeacherRelation(String termCourseId) {
        List<TermTeacherRelationDTO> termTeacherRelation = baseMapper.getTermTeacherRelation(termCourseId);
        // 字段的转换int -- String
        return termTeacherRelation.stream().map(relation -> {
            if (MALE_TYPE.equals(relation.getTeacherSex())) {
                relation.setTeacherSex(MALE);
            } else {
                relation.setTeacherSex(FEMALE);
            }
            if (ASSISTANT_TYPE.equals(relation.getTeacherType())) {
                relation.setTeacherType(ASSISTANT_TEACHER);
            } else {
                relation.setTeacherType(MAIN_TEACHER);
            }
            return relation;
        }).collect(Collectors.toList());
    }
}
